package com.hkyl.hospital.service.impl;

import com.github.pagehelper.PageHelper;
import com.hkyl.hospital.entity.Medicine;
import com.hkyl.hospital.mapper.MedicineMapper;
import com.hkyl.hospital.mapper.custom.CusMedicineMapper;
import com.hkyl.hospital.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author gao
 * @date 2023/07/10 16:42:58
 */
@Service
@Transactional
public class MedicineServiceImpl implements MedicineService {
@Autowired
private CusMedicineMapper medicineMapper;
    @Override
    public List<Medicine> findAll() {
        List<Medicine> medicines = medicineMapper.selectByExample(null);
        return medicines;
    }

    @Override
    public Medicine findOne(Integer id) {
        Medicine medicine = medicineMapper.selectByPrimaryKey(id);
        return medicine;
    }

    @Override
    public int save(Medicine medicine) {
        int i = medicineMapper.insertSelective(medicine);
        return i;
    }

    @Override
    public int update(Medicine medicine) {
        int i = medicineMapper.updateByPrimaryKeySelective(medicine);
        return i;
    }

    @Override
    public int delete(Integer id) {
        int i = medicineMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public List<Medicine> findSomeByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return medicineMapper.selectByExample(null);
    }

    @Override
    public int changeStatus(Integer id) {
        int i = medicineMapper.changeStatus(id);
        return i;
    }

    @Override
    public List<String> getUseMedicineType() {
        return medicineMapper.useMedicineType();
    }
}
